﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RbacMan.Repository
{
    public class BaseRepository<T> where   T : class
    {

        RbacManDbcontext db;


        public BaseRepository(RbacManDbcontext db)
        {
            this.db = db;
        }



        //查询
        public IQueryable<T> GetAll()
        {
            return db.Set<T>().AsQueryable();
        }

        //添加
        public int Add(T entity)
        {
            db.Set<T>().Add(entity);
            return db.SaveChanges();
        }
      /// <summary>
      /// 修改-逻辑删除
      /// </summary>
      /// <param name="entity"></param>
      /// <returns></returns>
        public int Update(T entity)
        {
            db.Set<T>().Update(entity);
            return db.SaveChanges();
        }

        //批量删除
        public int DeleteRange(List<T> entity)
        {
            db.Set<T>().RemoveRange(entity);
            return db.SaveChanges();
        }
    }
}
